package com.hps.ssh.dao.impl;

import com.hps.ssh.dao.IClassDao;
import com.hps.ssh.entity.Clazz;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ClassDaoImpl implements IClassDao {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public void addClass(Clazz clazz) {
        sessionFactory.getCurrentSession().save(clazz);
    }

    @Override
    public Clazz findById(Integer id) {
        String hql = "from Clazz where id=:id";
        Query query = sessionFactory.getCurrentSession().createQuery(hql);
        query.setParameter("id", id);
        return (Clazz) query.uniqueResult();
    }
}
